package randomstr

import (
	"crypto/rand"
	"math/big"
)

func Makerandint(data int) (int, error) {
	rnd, err := rand.Int(rand.Reader, big.NewInt(int64(data)))
	return int(rnd.Uint64()), err
}

func Makerandomstr(min, max int) string {
	str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	bytes := []byte(str)
	result := []byte{}
	var length int
	if min < max {
		rnd, err := rand.Int(rand.Reader, big.NewInt(int64(max-min)))
		if err != nil {
			return ""
		}
		length = min + int(rnd.Uint64())
	} else if min == max {
		length = min
	} else {
		return ""
	}
	for i := 0; i < length; i++ {
		rrnd, err := rand.Int(rand.Reader, big.NewInt(100000000))
		if err != nil {
			return ""
		}
		//rrnd随机整数，对字符串长度求模，随机索引
		result = append(result, bytes[int(rrnd.Uint64())%len(str)])
	}
	return string(result)
}
